From: Jeroen van der Heijden Date: Mon, 8 Oct 2018 12:12:07 +0000 (+0200) Subject: Added lookup test for deviding series equal across pools X-Git-Tag: archive/raspbian/2.0.44-1+rpi1~1^2~3^2~8^2~22 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=65cf2e32d51867a56d3cb9ead094a8d9b59a9924;p=siridb-server.git Added lookup test for deviding series equal across pools --- diff --git a/src/siri/db/series.c b/src/siri/db/series.c index 232a3496..563539a1 100644 --- a/src/siri/db/series.c +++ b/src/siri/db/series.c @@ -1392,7 +1392,7 @@ static siridb_series_t * SERIES_new( (uint16_t) ((n / 11) % siridb->shard_mask_log) + 600 : (uint16_t) ((n / 11) % siridb->shard_mask_num); - if ((uint8_t) ((n / 11) % 2)) + if ((_Bool) ((n / 11) % 2)) { series->flags |= SIRIDB_SERIES_IS_SERVER_ONE; } diff --git a/test/test_lookup/test_lookup.c b/test/test_lookup/test_lookup.c index fb37f0e6..ec065a33 100644 --- a/test/test_lookup/test_lookup.c +++ b/test/test_lookup/test_lookup.c @@ -3,6 +3,23 @@ #include +/* to at least 42 pools we devide series within 20% off from ideal */ +#define NPOOLS 42 + +static double percentage_unequal = 0.2; +static unsigned int countersa[NPOOLS]; +static unsigned int countersb[NPOOLS]; + +static void init_counters(void) +{ + unsigned int i; + for (i = 0; i < NPOOLS; ++i) + { + countersa[i] = 0; + countersb[i] = 0; + } +} + int main() { test_start("lookup"); @@ -10,8 +27,44 @@ int main() unsigned int i; siridb_lookup_t * lookup; uint16_t match[30] = { - 0, 1, 0, 2, 3, 1, 0, 3, 3, 2, 2, 1, 0, 1, 0, - 2, 3, 1, 0, 3, 3, 2, 2, 1, 0, 1, 0, 2, 3, 1}; + 0, 1, 0, 2, 3, 1, 0, 3, 3, 2, 2, 1, 0, 1, 0, + 2, 3, 1, 0, 3, 3, 2, 2, 1, 0, 1, 0, 2, 3, 1 + }; + + /* make sure the lookup zie has not changed */ + _assert(SIRIDB_LOOKUP_SZ == 8192); + + { + unsigned int num_pools; + for (num_pools = 1; num_pools < NPOOLS; ++num_pools) + { + unsigned int n, p, ideal, lower, upper; + ideal = SIRIDB_LOOKUP_SZ / (num_pools * 2); + lower = ideal - (percentage_unequal * ideal); + upper = ideal + (percentage_unequal * ideal); + init_counters(); + lookup = siridb_lookup_new(num_pools); + _assert (lookup); + for (n = 0; n < SIRIDB_LOOKUP_SZ; ++n) + { + /* check for SIRIDB_SERIES_IS_SERVER_ONE flag */ + if ((_Bool) ((n / 11) % 2)) + { + countersa[(*lookup)[n]]++; + } + else + { + countersb[(*lookup)[n]]++; + } + } + for (p = 0; p < num_pools; ++p) + { + _assert (countersa[p] >= lower && countersa[p] <= upper); + _assert (countersb[p] >= lower && countersb[p] <= upper); + } + free(lookup); + } + } lookup = siridb_lookup_new(4); _assert (lookup);